import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/user/index',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'user',
        meta: { title: '用户管理', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    redirect: '/project/index',
    meta: { title: '项目管理', icon: 'el-icon-document' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/project/index'),
        name: 'damin',
        meta: { title: '项目列表', icon: 'el-icon-notebook-1' }
      },
      {
        path: 'category',
        component: () => import('@/views/project/list'),
        name: 'gray',
        meta: { title: '项目分类', icon: 'el-icon-menu' }
      }
    ],
  },
  {
    path: '/test',
    component: Layout,
    redirect: '/test/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/test/index'),
        name: 'test',
      },
      {
        path: 'index1/:id',
        component: () => import('@/views/test/index'),
        name: 'test1'
      }
    ],
    hidden:true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
  // {
  //   path: '/private',
  //   component: Layout,
  //   redirect: '/private/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/private/index'),
  //       name: 'private',
  //       meta: { title: '个人', icon: 'dashboard' }
  //     }
  //   ]
  // },
  // 404 page must be placed at the end !!!
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
